###############################################
# === xenomorph_captive_development_triggers.txt ===
###############################################
###############################################
# XENOMORPH CAPTIVE DEVELOPMENT - scripted triggers (Layer 1)
# Submission-stage + vitality-threshold checks (LEADER scope).
#   xeno_submission : 0..100 (Defiant<20, Yielding<45, Submissive<70, Broken<95, Devoted>=95)
#   xeno_vitality   : 0..100
###############################################

# ---------------------------------------------------------------------------
# SUBMISSION STAGE TRIGGERS (leader scope)
# ---------------------------------------------------------------------------
xeno_captive_is_defiant = {
	has_variable = xeno_submission
	check_variable = { which = xeno_submission value < 20 }
}

xeno_captive_is_yielding = {
	check_variable = { which = xeno_submission value >= 20 }
	check_variable = { which = xeno_submission value < 45 }
}

xeno_captive_is_submissive = {
	check_variable = { which = xeno_submission value >= 45 }
	check_variable = { which = xeno_submission value < 70 }
}

xeno_captive_is_broken = {
	check_variable = { which = xeno_submission value >= 70 }
	check_variable = { which = xeno_submission value < 95 }
}

xeno_captive_is_devoted = {
	check_variable = { which = xeno_submission value >= 95 }
}

# "Broken or beyond" convenience (vitality no longer regenerates at/after this)
xeno_captive_is_broken_or_beyond = {
	check_variable = { which = xeno_submission value >= 70 }
}

# Vitality affordability check. Pass the cost via a saved scope is awkward in
# triggers, so we expose discrete checks used by the menu option potentials.
xeno_captive_vitality_atleast_10 = { check_variable = { which = xeno_vitality value >= 10 } }

xeno_captive_vitality_atleast_20 = { check_variable = { which = xeno_vitality value >= 20 } }

xeno_captive_vitality_atleast_25 = { check_variable = { which = xeno_vitality value >= 25 } }

xeno_captive_vitality_atleast_35 = { check_variable = { which = xeno_vitality value >= 35 } }

xeno_captive_vitality_atleast_40 = { check_variable = { which = xeno_vitality value >= 40 } }

###############################################
# === xenomorph_scripted_triggers_combined.txt ===
###############################################
###############################################
# XENOMORPH SCRIPTED TRIGGERS - COMBINED UPDATED FILE
# Put in: common/scripted_triggers/xenomorph_scripted_triggers_combined.txt
# Use this instead of the separate trigger files if you prefer one trigger file.
###############################################

#############################################
# POP / SPECIES SCOPE
#############################################

is_xenomorph = {
	species = { has_trait = trait_xenomorph }
}

#############################################
# COUNTRY SCOPE / CORE EMPIRE CHECKS
#############################################

xeno_is_xenomorph_hive_country = {
	is_hive_empire = yes
	OR = {
		owner_main_species = { has_trait = trait_xenomorph }
		has_origin = origin_xenomorph_prime
		has_origin = origin_xenomorph_queen_mother
		has_origin = origin_xenomorph_lab_escape
		has_origin = origin_xenomorph_scattered_brood
		has_origin = origin_xenomorph_crashed_derelict
	}
}

is_xenomorph_empire = { xeno_is_xenomorph_hive_country = yes }
is_xenomorph_tradition_empire = { xeno_is_xenomorph_hive_country = yes }

#############################################
# CIVIC / SEX-HIVE CHECKS
#############################################

xeno_is_matriarchal_hunger_empire = {
	OR = {
		has_valid_civic = civic_xenomorph_matriarchs_hunger
		has_civic = civic_xenomorph_matriarchs_hunger
	}
}

xeno_is_patriarchal_dominion_empire = {
	OR = {
		has_valid_civic = civic_xenomorph_patriarchs_dominion
		has_civic = civic_xenomorph_patriarchs_dominion
	}
}

xeno_is_patriarch_dominion_empire = { xeno_is_patriarchal_dominion_empire = yes }

is_xenomorph_sex_hive_civic = {
	OR = {
		xeno_is_matriarchal_hunger_empire = yes
		xeno_is_patriarchal_dominion_empire = yes
	}
}

#############################################
# PLANET SCOPE / ROYAL PRESENCE
#############################################

xeno_has_planetary_queen_presence = {
	OR = {
		# All capital tiers that contain queen-tier presence.
		has_building = building_xenomorph_queens_nest_1
		has_building = building_xenomorph_planetary_hive
		has_building = building_xenomorph_matriarch_hive
		has_building = building_xenomorph_brood_queen_hive
		has_building = building_xenomorph_empress_hive
		has_building = building_xenomorph_war_matriarch_hive
		has_building = building_xenomorph_queen_mother_hive
		has_modifier = xeno_planetary_queen_presence
		any_owned_pop = { has_job = xenomorph_queen_mother }
		any_owned_pop = { has_job = xenomorph_queen_mother_gestalt }
		any_owned_pop = { has_job = xenomorph_empress }
		any_owned_pop = { has_job = xenomorph_empress_gestalt }
		any_owned_pop = { has_job = xenomorph_queen }
		any_owned_pop = { has_job = xenomorph_queen_gestalt }
		any_owned_pop = { has_job = xenomorph_brood_queen }
		any_owned_pop = { has_job = xenomorph_brood_queen_gestalt }
		any_owned_pop = { has_job = xenomorph_matriarch }
		any_owned_pop = { has_job = xenomorph_matriarch_gestalt }
		any_owned_pop = { has_job = xenomorph_war_matriarch }
		any_owned_pop = { has_job = xenomorph_war_matriarch_gestalt }
		any_owned_pop = { has_job = xenomorph_paladin }
		any_owned_pop = { has_job = xenomorph_paladin_gestalt }
	}
}

xeno_can_build_royal_jelly_pools = {
	xeno_has_planetary_queen_presence = yes
	NOT = { has_building = building_xenomorph_royal_jelly_pools }
}

#############################################
# VANILLA BUILDING LOCKOUT
#############################################

xeno_vanilla_building_not_available_to_xenomorph_hive = {
	OR = {
		NOT = { exists = owner }
		owner = { NOT = { xeno_is_xenomorph_hive_country = yes } }
	}
}

#############################################
# HOSTLINE EVOLUTION - POP SCOPE
#############################################

xeno_host_is_reptilian = { species = { is_species_class = REP } }
xeno_host_is_avian = { species = { is_species_class = AVI } }
xeno_host_is_mammalian = { species = { is_species_class = MAM } }
xeno_host_is_arthropoid = { species = { is_species_class = ART } }
xeno_host_is_molluscoid = { species = { is_species_class = MOL } }
xeno_host_is_lithoid = { species = { is_species_class = LIT } }
xeno_host_is_necroid = { species = { is_species_class = NECROID } }
xeno_host_is_aquatic = {
	species = {
		OR = {
			has_trait = trait_aquatic
			is_species_class = AQUATIC
		}
	}
}
xeno_host_is_psionic = { species = { has_trait = trait_psionic } }
xeno_host_is_cybernetic = { species = { has_trait = trait_cybernetic } }

#############################################
# LUSTFUL VOID COMPAT - COUNTRY SCOPE
#############################################

xeno_has_any_slave_pop = {
	any_owned_pop = { is_enslaved = yes }
}

xeno_has_enslaved_all_male_species = {
	any_owned_pop = {
		is_enslaved = yes
		species = { has_trait = trait_lv_all_male }
	}
}

xeno_has_enslaved_all_female_species = {
	any_owned_pop = {
		is_enslaved = yes
		species = { has_trait = trait_lv_all_female }
	}
}

#############################################
# TRADITIONS / ASCENSION - COUNTRY SCOPE
#############################################

has_xenomorph_genetic_and_ovomorph_traditions = {
	has_tradition = tr_xenomorph_genetic_accumulation_finish
	has_tradition = tr_xenomorph_ovomorph_ascendancy_finish
}

has_xenomorph_voidbrood_path_unlocked = {
	has_ascension_perk = ap_xenomorph_voidbrood_parasitism
	has_country_flag = xenomorph_voidbrood_adaptation_complete
}

can_unlock_xenomorph_draconic_path = {
	has_tradition = tr_xenomorph_voidbrood_domestication_finish
	has_country_flag = xenomorph_voidbrood_adaptation_complete
}


# True if the pop has any sub-species hostline trait — i.e., is a "hostline hybrid".
# Used by the xenomorph_hostline_hybrid_warrior job to gate worker eligibility.
is_xenomorph_hostline_hybrid_pop = {
	OR = {
		has_trait = trait_xeno_mammalian_host
		has_trait = trait_xeno_arboreal_host
		has_trait = trait_xeno_acid_gland
		has_trait = trait_xeno_carapace_heavy
		has_trait = trait_xeno_adrenal
		has_trait = trait_xeno_aquatic_host
		has_trait = trait_xeno_spore_host
		has_trait = trait_xeno_reptilian_host
		has_trait = trait_xeno_lithoid_host
		has_trait = trait_xeno_cybernetic_host
	}
}

# Pass 20: Used by the offspring/egg economy unlock techs.
# True when the empire owns a sapient non-Xenomorph species that doesn't
# have full citizenship (i.e. enslaved, livestock, purge, etc.). Mirrors
# the vanilla pattern for detecting "has this empire engaged with non-citizen
# subject species" — covers conquest pops in slave/purge status, captured
# slaves from raids, and any other case where a non-Xeno species lives in
# the empire under non-citizen status.
xeno_has_enslaved_or_conquered_species = {
	any_owned_species = {
		NOT = { has_trait = trait_xenomorph }
		NOT = { has_trait = trait_mechanical }
		NOT = { has_trait = trait_machine_unit }
		is_sapient = yes
		NOT = { has_citizenship_type = { type = citizenship_full country = root } }
	}
}

# Pass 37a: True if the empire has finished at least one of the 3 foundational
# Xenomorph tradition trees. Used to gate the 2nd-tier core trees
# (silent_infestation, subjugated_flesh) behind some tradition progression.
has_xenomorph_one_tree_finished = {
	OR = {
		has_tradition = tr_xenomorph_genetic_accumulation_finish
		has_tradition = tr_xenomorph_ovomorph_ascendancy_finish
		has_tradition = tr_xenomorph_royal_hierarchy_finish
	}
}

#############################################
# CAPTOR (non-hive) TRIGGERS
# For empires that exploit captured Xenomorphs rather than being them.
#############################################

# A non-hive empire that has access to Xeno exploitation (the captor playstyle).
is_xeno_captor_empire = {
	is_gestalt = no
	OR = {
		has_technology = tech_xeno_containment
		any_owned_pop_group = { is_xenomorph = yes }
		any_owned_planet = { has_deposit = d_pacified_xenomorphs }
		any_owned_planet = { has_deposit = d_feral_xenomorphs }
	}
}

# A non-hive empire eligible to START a captor tradition tree.
is_xeno_captor_tradition_empire = {
	is_gestalt = no
	OR = {
		has_technology = tech_xeno_containment
		any_owned_pop_group = { is_xenomorph = yes }
		has_origin = origin_xeno_traffickers
		has_origin = origin_xeno_keepers
	}
}

# FIX 2026-07: Planet scope. True for any of the mod's 20 Xenomorph planet
# classes (hive/tentacle/ringworld/ecumenopolis/ocean x base/fortress/brood/foundry).
# Added because xenogeneral.5 / xeno_hive_world.10 only checked pc_hive and
# pc_xenomorph_hive, so wild-colonized Tendril Worlds never received the
# xenomorph_hive_world flag/modifier.
xeno_is_xenomorph_planet_class = {
	OR = {
		is_planet_class = pc_xenomorph_hive
		is_planet_class = pc_xenomorph_hive_fortress
		is_planet_class = pc_xenomorph_hive_brood
		is_planet_class = pc_xenomorph_hive_foundry
		is_planet_class = pc_xenomorph_tentacle
		is_planet_class = pc_xenomorph_tentacle_fortress
		is_planet_class = pc_xenomorph_tentacle_brood
		is_planet_class = pc_xenomorph_tentacle_foundry
		is_planet_class = pc_xenomorph_infested_ringworld
		is_planet_class = pc_xenomorph_infested_ringworld_fortress
		is_planet_class = pc_xenomorph_infested_ringworld_brood
		is_planet_class = pc_xenomorph_infested_ringworld_foundry
		is_planet_class = pc_xenomorph_infested_ecumenopolis
		is_planet_class = pc_xenomorph_infested_ecumenopolis_fortress
		is_planet_class = pc_xenomorph_infested_ecumenopolis_brood
		is_planet_class = pc_xenomorph_infested_ecumenopolis_foundry
		is_planet_class = pc_xenomorph_infested_ocean
		is_planet_class = pc_xenomorph_infested_ocean_fortress
		is_planet_class = pc_xenomorph_infested_ocean_brood
		is_planet_class = pc_xenomorph_infested_ocean_foundry
	}
}

# FIX 3_61: were called by xeno_captive_spawn_leader_from_kill but never defined.
xeno_captive_is_commander = {
	leader_class = commander
}

xeno_captive_is_scientist = {
	leader_class = scientist
}
